﻿//-----------------------------------------------------------------------
// <copyright file="Copyright.cs" author="Michael Herndon">
//     Copyright (c) Michael Herndon.  All rights reserved.
// </copyright>
//-----------------------------------------------------------------------

namespace Amplify.Twitter
{
	using System;
	using System.Collections.Generic;
	using System.Globalization;
	using System.Linq;
	using System.Text;
	using System.Runtime.Serialization;

	/// <summary>
	/// A Data Transfer Object (DTO) that represents a status message (tweet) 
	/// from twitter.
	/// </summary>
	/// <remarks>
	///		<para>
	///			It represents the &quot;status&quot; element/object in both the xml and 
	///			json portions of the REST responses. 
	///		</para>
	/// </remarks>
	[DataContract(Name = "status")]
	public class Status : TwitterError 
	{
		private string createdAtString = "";
		private DateTime createdAt = DateTime.MinValue;

		/// <summary>
		/// Gets the constant value of the DateTime format.  
		/// </summary>
		public const string TimeFormat = "ddd MMM dd HH:mm:ss zzzz yyyy";

		/// <summary>
		/// Gets or sets unique integer id of the status/tweet. 
		/// </summary>
		/// <remarks>
		///		<para>
		///			The json key or xml attribute will be &quot;id&quot;.
		///		</para>
		/// </remarks>
		[DataMember(Name="id")]
		public int? Id { get; set; }

		/// <summary>
		/// Gets or sets <see cref="System.String"/> value of the Date/Time the tweet was created.
		/// </summary>
		/// <remarks>
		///		<para>
		///		The json key or xml attribute will be &quot;created_at&quot;.
		///		The string format from twitter is &quot;ddd MMM dd HH:mm:ss zzzz yyyy&quot;
		///		</para>
		/// </remarks>
		[DataMember(Name = "created_at")]
		public string CreatedAtString 
		{
			get { return this.createdAtString; }
			set {
				this.createdAtString = value;
				if (!string.IsNullOrEmpty(value))
				{
					this.createdAt = DateTime.ParseExact(
						value, TimeFormat,
						 CultureInfo.CurrentCulture, DateTimeStyles.AllowWhiteSpaces);
				}
			}
		}

		/// <summary>
		/// Gets or sets <see cref="System.DateTime"/> value of the created_at value from  
		/// twitter, if it can be parsed. 
		/// </summary>
		public DateTime CreatedAt
		{
			get
			{
				return this.createdAt;
			}
			set
			{
				this.createdAt = value;
				this.createdAtString = value.ToString(TimeFormat);
			}
		}

		/// <summary>
		/// Gets or sets the textual content of the tweet.
		/// </summary>
		/// <remarks>
		///		<para>
		///			The json key or xml attribute will be &quot;text&quot;.
		///		</para>
		/// </remarks>
		[DataMember(Name="text")]
		public string Text { get; set; }

		/// <summary>
		/// Gets or sets the source (application) that this tweet was created by.
		/// </summary>
		/// <remarks>
		///		<para>
		///			The json key or xml attribute will be &quot;source&quot;.
		///		</para>
		/// </remarks>
		[DataMember(Name = "source")]
		public string Source { get; set; }
		
		/// <summary>
		/// Gets or sets the flag that determines if the message was truncated.
		/// </summary>
		/// <remarks>
		///		<para>
		///			The json key or xml attribute will be &quot;truncated&quot;.
		///		</para>
		/// </remarks>
		[DataMember(Name="truncated")]
		public bool IsTruncated { get; set; }

		/// <summary>
		/// Gets or sets the id of the message that this tweet is a reply to.
		/// </summary>
		/// <remarks>
		///		<para>
		///			The json key or xml attribute will be &quot;in_reply_to_status_id&quot;.
		///		</para>
		/// </remarks>
		[DataMember(Name="in_reply_to_status_id")]
		public int? ReplyToStatusId { get; set;}

		/// <summary>
		/// Gets or sets the user id of the message that this tweet is a reply to.
		/// </summary>
		/// <remarks>
		///		<para>
		///			The json key or xml attribute will be &quot;in_reply_to_user_id&quot;.
		///		</para>
		/// </remarks>
		[DataMember(Name ="in_reply_to_user_id")]
		public int? ReplyToUserId { get; set; }

		/// <summary>
		/// Gets or sets the flag that determines if this tweet is a favorite.
		/// </summary>
		/// <remarks>
		///		<para>
		///			The json key or xml attribute will be &quot;favorited&quot;.
		///		</para>
		/// </remarks>
		[DataMember(Name = "favorited")]
		public bool? IsFavorite { get; set; }

		/// <summary>
		/// Gets or sets the <see cref="Amplify.Twitter.User"/> owner of this tweet.
		/// </summary>
		/// <remarks>
		///		<para>
		///			The json key or xml attribute will be &quot;user&quot;.
		///		</para>
		/// </remarks>
		[DataMember(Name = "user")]
		public User User { get; set; }
	}
}
